package com.itheima.crm.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itheima.common.utils.Page;

import com.itheima.crm.mapper.OrganizationDao;

import com.itheima.crm.pojo.Organization;
import com.itheima.crm.service.OrganizationService;

/**
 * 客户管理
 * 
 * @author lx
 *
 */
@Service
public class OrganizationServiceImpl implements OrganizationService {

	@Autowired
	private OrganizationDao organizationdao;

	// 通过四个条件 查询分页对象
	public Page<Organization> selectOrganization(Organization vo) {
		Page<Organization> page = new Page<Organization>();
		// 每页数
		page.setSize(5);
		vo.setSize(5);
		if (null != vo) {
			// 判断当前页
			if (null != vo.getPage()) {
				page.setPage(vo.getPage());
				vo.setStartRow((vo.getPage() - 1) * vo.getSize());
			}

			// 总条数
			page.setTotal(organizationdao.OrganizationCount(vo));
			page.setRows(organizationdao.selectOrganization(vo));
		}
		return page;

	}

	// 通过ID查询客户
	public Organization selectOrganizationById(Integer id) {
		return organizationdao.selectOrganizationById(id);
	}

	// 修改客户通过ID
	public void updateOrganizationById(Organization organization) {
		organizationdao.updateOrganizationById(organization);
	}

	// 通过ID 删除客户
	public void deleteOrganization(Organization organization) {
		organizationdao.deleteOrganization(organization);
	}

	@Override
	public void insertOrganization(Organization organization) {
		organizationdao.insertOrganization(organization);

	}

	@Override
	public void updateOrganizationCount() {
		// TODO Auto-generated method stub
		organizationdao.updateOrganizationCount();
	}

	@Override
	public Organization selectOrganizationByOname(String oname) {
		// TODO Auto-generated method stub
		return organizationdao.selectOrganizationByOname(oname);
	}

	@Override
	public void updateOrganizationCountto0(String org) {
		organizationdao.updateOrganizationCountto0(org);

	}

	@Override
	public void updateManager(Organization o) {
		organizationdao.updateManager(o);
		
	}
}
